<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box">图片加载中</div>
    
    <script>

        var box = document.getElementById("box");
        function loadImageAsync(url){
            const promise = new Promise(function(resolve,reject){
                const image = new Image();
                image.src = url;
                image.onload = function(){
                    resolve(image);
                }
                image.onerror = function(){
                    reject(new Error("Could not load image at" + url))
                }
            })
            return promise;
        }

        const promise = loadImageAsync("http://gips3.baidu.com/it/u=1821127123,1149655687&fm=3028&app=3028&f=JPEG&fmt=auto?w=720&h=1280");
        promise.then(function(data){
            box.appendChild(data)

        },function(error){
            box.innerHTML = "图片加载失败";
            console.log("error");
            
        })
    </script>
</body>
</html>